﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StyleMVVM.Data.Transform
{
	public class TransformMap<TIn, TOut> : ITransformMap<TIn, TOut>, ITransformMapInfo
	{
		private readonly ITransformService transformService;

		private readonly List<TransformPropertyMap<TIn, TOut>> properties =
			new List<TransformPropertyMap<TIn, TOut>>();

		public TransformMap(ITransformService transformService)
		{
			this.transformService = transformService;
		}

		ITransformMap<TIn, TOut> ITransformMap<TIn, TOut>.IsLooseTransform(bool isLoose)
		{
			IsLooseTransform = isLoose;

			return this;
		}

		public ITransformPropertyMap<TIn, TOut> MapProperty
		{
			get
			{
				var returnValue = new TransformPropertyMap<TIn, TOut>(this);

				properties.Add(returnValue);

				return returnValue;
			}
		}

		public void MapComplete()
		{
			transformService.AddTransforms(this);
		}

		public bool IsLooseTransform { get; private set; }

		public Type InType
		{
			get { return typeof(TIn); }
		}

		public Type OutType
		{
			get { return typeof(TOut); }
		}

		public IEnumerable<ITransformPropertyMapInfo> MappedProperties()
		{
			return properties;
		}
	}
}